package cate.game.role.fight;

import com.fasterxml.jackson.annotation.JsonIgnore;
import cp.solution.util.collection.ListKit;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@NoteClass("一个功能里的阵法")
public class FuncPosition {

	@NoteField("功能id")
	public int funcId;

	@NoteField(value = "各个队伍",detail = "")
	public List<Position> positions = new ArrayList<>();

	public void init() {
		if (positions == null) {
			positions = new ArrayList<>();
		}
	}

	@JsonIgnore
	public Position getPosition(int num) {
		for (Position position : positions) {
			if (position.posNum == num) {
				return position;
			}
		}
		return null;
	}

	public void clear() {
		if (positions != null) {
			positions.clear();
		}
	}

	public FuncPosition copy(){
		FuncPosition cp = new FuncPosition();
		cp.funcId = this.funcId;
		cp.positions = ListKit.cloneList(positions,Position::copy);
		return cp;
	}

	public boolean containHero(String heroUid){
		for (Position position : positions) {
			for (HeroGrid grid : position.grids) {
				if(StringUtils.equals(grid.uid, heroUid)){
					return true;
				}
			}
		}
		return false;
	}
}
